//
//  RHDeviceChartDataCell.m
//  RuiHeAppApp
//
//  Created by Jun on 2023/7/27.
//

#import "RHDeviceChartDataCell.h"

#import "DeviceChartView.h"

@interface RHDeviceChartDataCell()

@property (nonatomic ,strong) DeviceChartView *chartView;

@end

@implementation RHDeviceChartDataCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

- (void)setChartModel:(DevChartModel *)chartModel{
    _chartModel = chartModel;

    [_chartView setChartModel:_chartModel];
}

-(void)hideSelectBtn:(BOOL)isHide
{
    [self.chartView hideSelectBtn:isHide];
}

- (void)setupUI{
    
    [self setBackgroundColor:CFTabViewBgColor];
    [self.contentView setBackgroundColor:CFTabViewBgColor];
    
    UIView *bgView = [[UIView alloc] init];
    [bgView.layer setCornerRadius:0];
    [bgView setBackgroundColor:UIColor.whiteColor];
    [self.contentView addSubview:bgView];
    
    [bgView setMiddleBorder];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    NSInteger type = 2;
    if ([self.reuseIdentifier containsString:@"Month"]) {
        type = 1;
    }
    if ([self.reuseIdentifier containsString:@"Day"]) {
        type = 2;
    }
    if ([self.reuseIdentifier containsString:@"Year"]) {
        type = 0;
    }
    _chartView = [[DeviceChartView alloc] initWithFrame:CGRectMake(5, 5,SCREEN_WIDTH-40, 250+130) type:type withIsLandscape:NO];
    [bgView addSubview:_chartView];
    kWeakSelf;
    _chartView.fullChartBlock = ^{
        if (weakSelf.fullChartBlock) {
            weakSelf.fullChartBlock();
        }
    };
    _chartView.selectTopToolBlock = ^(NSInteger index) {
        if (weakSelf.selectTopToolBlock) {
            weakSelf.selectTopToolBlock(index);
        }
    };
    
    _chartView.subTimeBlock = ^{//日期往前
        if (weakSelf.subTimeBlock) {
            weakSelf.subTimeBlock();
        }
    };
    
    _chartView.addTimeBlock = ^{//日期往后
        if (weakSelf.addTimeBlock) {
            weakSelf.addTimeBlock();
        }
    };
    
    _chartView.changeTimeBlock = ^{
        if (weakSelf.changeTimeBlock) {
            weakSelf.changeTimeBlock();
        }
    };
    
    
    [_chartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(5);
        make.right.mas_offset(-5);
        make.top.mas_offset(5);
        make.bottom.mas_offset(0);
//        make.height.mas_equalTo(kScaleW(380));
    }];
}




@end
